跳到主要内容

GetCommentById

Returns a comment from the current document by its ID.

Syntax

expression.GetCommentById(sId);

expression - A variable that represents a ApiDocument class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sIdRequiredstringThe comment ID.

Returns

ApiComment

Example

This example shows how to get a comment from the document by its ID.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
paragraph.AddText("This is just a sample text");
Api.AddComment(paragraph, "comment", "John Smith");
let comments = doc.GetAllComments();
let id = comments[0].GetId();
let comment = doc.GetCommentById(id);
let author = comment.GetAutorName();
paragraph = Api.CreateParagraph();
paragraph.AddText("Comment author name: " + author);
doc.Push(paragraph);